import React, { useState } from 'react';
// 首页的样式表
import '../styles/pages/index.css'
// 公共头部
import Header from '../components/Header'
// 身份认证
import Idcard from '../components/Idcard'
// 广告组件
// import Advert from '../components/Advert'
// 底部copy
import { Row, Col, List, Affix } from 'antd'
import Link from 'next/link'
import axios from 'axios'


import Footer from '../components/Foot';
// 服务地址的管理
import servicePath from '../config/apiUrl'

const Home = (list) => {
  const [mylist, setMylist] = useState(list.data);
  return (
    <div>
      <Affix offsetTop={0}>
        <Header className="header"></Header>
      </Affix>
      {/* // 双栏布局 */}
      <Row className="comm-main" type='flex' justify='center'>
        <Col className="comm-left" xs={24} sm={24} md={15} lg={10} xl={13}>
          <div>
            <List
              size="large"
              dataSource={mylist}
              renderItem={item => (
                <List.Item>
                  <Link href={{ pathname: '/detail', query: { id: item.id } }}>
                    <a>{item.title}</a>
                  </Link>
                  <div className="list-icon">
                    <span><i className="iconfont">&#xe609;</i> {item.addTime}</span>
                    <span><i className="iconfont">&#xe64d;</i> {item.typeName}</span>
                  </div>
                  <div className="list-context">{item.introduce}</div>
                </List.Item>
              )}
            />
          </div>
        </Col>
        <Col className='comm-right' xs={0} sm={0} md={8} lg={4} xl={4}>
          <Idcard></Idcard>
        </Col>
      </Row>
      <Row className="comm-main" type='flex' justify='center'>
        <Col className='comm-right' xs={0} sm={0} md={8} lg={4} xl={4}>
        </Col>
      </Row>

      <Footer></Footer>
    </div>
  )
}

Home.getInitialProps = async () => {
  const promise = new Promise((resolve) => {
    axios(servicePath.getArticleList).then(
      (res) => {
        console.log(res)
        resolve(res.data)
      }
    )
  })

  return await promise
}

export default Home
